----------------------------------Spell Variables--------------------------------------
SPELL.m_iSpellID = 15412 -- Whatever value you want as long as it doesn't override any other spells' IDs.
SPELL.m_iRange = 1024
SPELL.m_sName = "Mana Explosion"
SPELL.m_sToolTip =	[[You unleash pure
					energy in all directions,
					dealing moderate magic
					damage to all targets nearby.]]
SPELL.m_sIcon = "devin/blackbetty/spells/mage/manaexplosion.png"
SPELL.m_iCoolDown = 0.25
SPELL.m_iManaCost = 25
SPELL.m_bRequiresTarget = false
SPELL.m_iSpellType = SPELLTYPE_RANGEDAMAGE

---------------------------------------------------------------------------------------

function SPELL:Cast( pl, target )
	
	print("Casted "..self.m_sName.."!")
	
	local range = self.m_iRange

	self:Effect(pl, target)

end

function SPELL:Effect(pl, target)

	local weapon = pl:GetWeapon("weapon_all")
	
	pl:DoAnimationEvent(ACT_HL2MP_GESTURE_RANGE_ATTACK_KNIFE)
	pl:EmitSound("devin/blackbetty/weapons/castsounds/ShadowCast.wav", 150, 130+math.random(10,20))
	if(SERVER)then
		local whirlRadius = ents.FindInSphere(pl:GetPos(), 240)
		pl:EmitSound("ambient/energy/zap"..math.random(1,9)..".wav", 150, 80+math.random(10,30))
		
		for i, s in ipairs(whirlRadius)do
			if(s and s:EntIndex() != pl:EntIndex() and s:IsPlayer() or s:IsNPC() or s:GetClass() == "npc_rpgdm")then
				ParticleEffect( "arcane_hit", s:GetPos() + Vector(0, 0, 32), Angle(0,0,0), s )
				self:DealDamage(weapon.MinWeaponDamage*1, weapon.MaxWeaponDamage*1, pl, s, DMG_ENERGYBEAM)
			end
		end
		
		local modeleffect = ents.Create("prop_dynamic")
		modeleffect:SetMoveParent(pl)
		modeleffect:SetPos(pl:GetPos() + Vector(0, 0, -38))
		modeleffect:SetAngles(pl:GetAngles())
		modeleffect:SetLocalAngles(Angle(0, 0, 0))
		modeleffect:SetModel(Model("models/XQM/Rails/gumball_1.mdl"))
		modeleffect:SetRenderMode(RENDERMODE_TRANSALPHA)
		modeleffect:SetMaterial("models/props_combine/portalball001_sheet.vmt")
		modeleffect:SetColor(Color(255, 128, 240, 80))
		modeleffect:DrawShadow( false )
		modeleffect:Spawn()
		modeleffect:Activate()
		local sequence = modeleffect:LookupSequence("idle")
		modeleffect:SetSequence(sequence)
		modeleffect:SetPlaybackRate(1.5)
		local inc = 20
		timer.Create(""..pl:GetName().."manaexplosionscale", 0.00625, 20, function()
			inc = inc - 1
			if(inc > 0)then
				modeleffect:SetModelScale( modeleffect:GetModelScale() * 1.15, 0 )
				modeleffect:Fire( "alpha", inc * 4, 0 )
			else
				modeleffect:Remove()
			end
		end)
		
		pl:EmitSound("devin/blackbetty/weapons/Exorcism.wav", 150, 80+math.random(10,30))
	end
end




